﻿using System;
using System.IO;
using System.Reflection;
using TasksDataXml.Data;

namespace TasksDataXml.Helpers
{
    public class PathUtility
    {
        public static string GetAppPath()
        {
            return System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        }

        public static string GetCategoriesPath(string root)
        {
            try
            {
                var path = root ?? GetAppPath();
                path = CategoryContainer.GetPath(path);
                return path;
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

        public static bool CheckDirectories(string filename)
        {
            if(string.IsNullOrEmpty(filename))
                return false;

            var dir = Path.GetDirectoryName(filename);
            if (string.IsNullOrEmpty(dir))
                return false;

            if(!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            return true;
        }
    }
}
